package com.yuntian.controller.admin;

import com.yuntian.Dto.ProductPageQueryDto;
import com.yuntian.entity.Product;
import com.yuntian.result.PageResult;
import com.yuntian.result.Result;
import com.yuntian.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/product")
public class ProductController {
    @Autowired
    private ProductService productService;
    /**
     * 商品列表
     */
    @GetMapping("/list")
    public Result<PageResult> list(
            ProductPageQueryDto productPageQueryDto) {

        PageResult pageResult = productService.list(productPageQueryDto);
        return Result.success(pageResult);
    }

    /**
     * 添加商品
     */
    /**
     * 商品新增
     */
    @PostMapping("/add")
    public Result insertProduct(@RequestBody Product product) {
        productService.insertProduct(product);
        return Result.success();
    }

    /**
     * 商品修改
     */
    @PutMapping("/update")
    public Result updateProduct(@RequestBody Product product) {
        productService.updateProduct(product);
        return Result.success();
    }

    /**
     * 商品删除
     */
    @DeleteMapping("/delete")
    public Result deleteProduct(@RequestBody Product product) {
        productService.deleteProduct(product);
        return Result.success();
    }
}
